package com.summer.dao.role;

import com.summer.dao.BaseDao;
import com.summer.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * 作者:夏天
 * qq:1205232048
 */
public class RoleDaoImpl implements RoleDao{
    /**
     * 根据连接 返回角色列表
     * @param connection
     * @return List<Role>
     * @throws Exception
     */
    public List<Role> getRoleList(Connection connection) throws Exception {
        List<Role> roles = new ArrayList<Role>();
        ResultSet resultSet = null;
        PreparedStatement preparedStatement = null;
        if(connection != null){
            String sql = "select * from smbms_role";
            Object params[] = {};
            resultSet = BaseDao.execute(connection, preparedStatement, resultSet, sql, params);
            while (resultSet.next()) {
                Role role = new Role();
                role.setId(resultSet.getInt("id"));
                role.setRoleCode(resultSet.getString("roleCode"));
                role.setRoleName(resultSet.getString("roleName"));
                roles.add(role);
            }
        }
        BaseDao.closeResource(connection,preparedStatement,resultSet);
        return roles;
    }
}
